<extend name="Layout/application"/>

<block name="content">
    <div class="row">
        <div class="col-md-12">

            <div class="row">
                <div class="col-md-8">
                    <div class="page-header">
                        <h1>友情链接</h1>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-10">
                    <div class="panel panel-default">
                        <div class="panel-heading">友情链接</div>
                        <div class="panel-body">
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" class="fchx"></th>
                                    <th></th>
                                    <th>名称</th>
                                    <th>地址</th>
                                    <a href="">
                                        <th class="sort">排序</th>
                                    </a>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <form action="" method="post" id="form">
                                    <volist name="links" id="l">
                                        <tr>
                                            <th><input type="checkbox" class="cchx" name="checked_id[]" value="{{$l.id}}"></th>
                                            <td class="id">{{$l.id}}</td>
                                            <td class="name"><a href="{{$l.url}}" target="_blank">{{$l.name}}</a></td>
                                            <td class="url"><a href="{{$l.url}}" target="_blank">{{$l.url}}</a></td>
                                            <input type="hidden" name="id[]" value="{{$l.id}}">
                                            <td class="sort_order">
                                                <input type="text" name="sort_order[]" value="{{$l.sort_order}}">
                                            </td>
                                            <td>
                                                <a href="" data-toggle="modal" data-target="#editModal"
                                                   class="edit"><span
                                                        class="glyphicon glyphicon-pencil"></span></a>

                                                <a href="{{:U('destory',array('id'=>$l['id']))}}"> <span
                                                        class="glyphicon glyphicon-trash"></span></a>

                                            </td>
                                        </tr>
                                    </volist>
                                </form>
                                </tbody>
                            </table>
                        </div>

                    </div>
                </div>


                <div class="col-md-2">
                    <div class="list-group">
                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sort_category"
                           data-toggle="modal" data-target="#create_link">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 新增 (add)
                        </a>

                        <a href="javascript: void 0;" class="list-group-item list-group-item-info sortby_order">
                            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 排序 (sort)
                        </a>
                        <a href="javascript: void 0;" class="list-group-item list-group-item-info delete_checked">
                            <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> 批量删除 (delete)
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="create_link" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="createModalLabel">新增友情链接</h4>
                </div>
                <form class="form-horizontal" role="form" method="post" action="{{:U('store')}}">

                    <div class="modal-body">
                        <div class="form-group">
                            <label for="cname" class="col-sm-2 control-label">名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="name" id="cname" placeholder="请输入名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="curl" class="col-sm-2 control-label">地址</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="url" id="curl" placeholder="请输入地址">
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <!-- Button trigger modal -->
    <!--<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">-->
    <!--Launch demo modal-->
    <!--</button>-->

    <!-- Modal -->
    <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">修改友情链接</h4>
                </div>
                <form class="form-horizontal" role="form" method="post" action="{{:U('update')}}">
                    <div class="modal-body">
                        <input type="hidden" name="id" id="edit_id" name="edit_id">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">名称</label>
                            <div class="col-sm-10">
                                <input type="text" name="name" id="edit_name" id="inputEmail3" placeholder="请输入名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label">地址</label>
                            <div class="col-sm-10">
                                <input type="text" name="url" id="edit_url" id="inputPassword3" placeholder="请输入地址">
                            </div>
                        </div>


                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>

        </div>
    </div>


</block>
<block name="js">
    <script>
        $(function () {
            $('.edit').click(function () {
//                console.log(111111);
                var id = $(this).parent().siblings('.id').text();
                var name = $(this).parent().siblings('.name').text();
                var url = $(this).parent().siblings('.url').text();
//                console.log(id);
                $('#edit_id').val(id);
                $('#edit_name').val(name);
                $('#edit_url').val(url);
            });


            $('.fchx').click(function () {
                $('.cchx').prop('checked', this.checked);
            });

            $('.delete_checked').click(function(){
                var l = $(".cchx:checked").length;
                if(l == 0){
                    alert('您必须选中一条数据');
                    return false;
                }
                $('#form').attr('action','{{:U("delete_checked")}}').submit();
            });

            $('.sortby_order').click(function () {
                $('#form').attr('action','{{:U("sort_order")}}').submit();
            });

        })
    </script>
</block>

